## SUR Models, Main Text ##

# Load Data #
MFQ20 <- read.table(file.choose(), header = TRUE)

# Party and Ideol Vars #
MFQ20$Party.cat <- NA
MFQ20$Party.cat[MFQ20$Party <= 3] <- "Democrat"
MFQ20$Party.cat[MFQ20$Party == 4] <- "Independent"
MFQ20$Party.cat[MFQ20$Party >= 5] <- "Republican"

MFQ20$Ideol.cat <- NA
MFQ20$Ideol.cat[MFQ20$Ideol <= 3] <- "Liberal"
MFQ20$Ideol.cat[MFQ20$Ideol == 4] <- "Moderate"
MFQ20$Ideol.cat[MFQ20$Ideol >= 5] <- "Conservative"

# Dep. Vars #
MFQ20$HarmTotal.1 <- ((MFQ20$Harm1 + MFQ20$Harm2 + MFQ20$Harm3) - 3)/15
MFQ20$FairTotal.1 <- ((MFQ20$Fair1 + MFQ20$Fair2 + MFQ20$Fair3) - 3)/15
MFQ20$IngroupTotal.1 <- ((MFQ20$Ingroup1 + MFQ20$Ingroup2 + MFQ20$Ingroup3 +
                            MFQ20$Ingroup4) - 4)/20
MFQ20$AuthTotal.1 <- ((MFQ20$Auth1 + MFQ20$Auth2 + MFQ20$Auth3) - 3)/15
MFQ20$PureTotal.1 <- ((MFQ20$Pure1 + MFQ20$Pure2 + MFQ20$Pure3 +
                         MFQ20$Pure4) - 4)/20

# Using SystemFit package to fit mods #
library(systemfit)

# Dems First #
DemDataParty <- MFQ20[MFQ20$Party.cat == "Democrat" & 
                        MFQ20$Treatment != "Ideol",]

vars <- c("HarmTotal.1", "FairTotal.1", "IngroupTotal.1", "AuthTotal.1",
          "PureTotal.1", "Treatment")

DemDataParty <- DemDataParty[vars]
DemDataParty <- na.omit(DemDataParty)

DemDataParty$P <- ifelse(DemDataParty$Treatment == "Party", 1, 0)
DemDataParty$PI <- ifelse(DemDataParty$Treatment == "P + I", 1, 0)

Harm <- HarmTotal.1 ~ P + PI
Fair <- FairTotal.1 ~ P + PI
Ingroup <- IngroupTotal.1 ~ P + PI
Auth <- AuthTotal.1 ~ P + PI
Pure <- PureTotal.1 ~ P + PI

SURDems <- systemfit(list(HarmReg = Harm, FairReg = Fair, IngroupReg = Ingroup,
                          AuthReg = Auth, PureReg = Pure), 
                     data = DemDataParty, method = "SUR")
summary(SURDems)

linearHypothesis(SURDems, "HarmReg_P - FairReg_P = 0")
linearHypothesis(SURDems, "-HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURDems, "HarmReg_P - IngroupReg_P = 0")
linearHypothesis(SURDems, "HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURDems, "HarmReg_P - AuthReg_P = 0")
linearHypothesis(SURDems, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems, "HarmReg_P - PureReg_P = 0")
linearHypothesis(SURDems, "HarmReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems, "FairReg_P - IngroupReg_P = 0")
linearHypothesis(SURDems, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURDems, "FairReg_P- AuthReg_P = 0")
linearHypothesis(SURDems, "-FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems, "FairReg_P - PureReg_P = 0") # Sig @ .10
linearHypothesis(SURDems, "-FairReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems, "IngroupReg_P - AuthReg_P = 0")
linearHypothesis(SURDems, "IngroupReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems, "IngroupReg_P - PureReg_P = 0") # Sig @ .10
linearHypothesis(SURDems, "IngroupReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems, "AuthReg_P - PureReg_P = 0")
linearHypothesis(SURDems, "AuthReg_PI - PureReg_PI = 0")


########
# Libs #
########

LibDataParty <- MFQ20[MFQ20$Ideol.cat == "Liberal" & 
                        MFQ20$Treatment != "Party",]

vars <- c("HarmTotal.1", "FairTotal.1", "IngroupTotal.1", "AuthTotal.1",
          "PureTotal.1", "Treatment")

LibDataParty <- LibDataParty[vars]
LibDataParty <- na.omit(LibDataParty)


LibDataParty$I <- ifelse(LibDataParty$Treatment == "Ideol", 1, 0)
LibDataParty$PI <- ifelse(LibDataParty$Treatment == "P + I", 1, 0)

Harm <- HarmTotal.1 ~ I + PI
Fair <- FairTotal.1 ~ I + PI
Ingroup <- IngroupTotal.1 ~ I + PI
Auth <- AuthTotal.1 ~ I + PI
Pure <- PureTotal.1 ~ I + PI


SURLibs <- systemfit(list(HarmReg = Harm, FairReg = Fair, IngroupReg = Ingroup,
                          AuthReg = Auth, PureReg = Pure), 
                     data = LibDataParty, method = "SUR")
summary(SURLibs)


linearHypothesis(SURLibs, "HarmReg_I - FairReg_I = 0")
linearHypothesis(SURLibs, "-HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURLibs, "HarmReg_I - IngroupReg_I = 0")
linearHypothesis(SURLibs, "HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURLibs, "HarmReg_I - AuthReg_I = 0")
linearHypothesis(SURLibs, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs, "HarmReg_I - PureReg_I = 0")
linearHypothesis(SURLibs, "HarmReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs, "FairReg_I - IngroupReg_I = 0")
linearHypothesis(SURLibs, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURLibs, "FairReg_I - AuthReg_I = 0")
linearHypothesis(SURLibs, "-FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs, "FairReg_I - PureReg_I = 0") 
linearHypothesis(SURLibs, "-FairReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURLibs, "IngroupReg_I - AuthReg_I = 0") 
linearHypothesis(SURLibs, "IngroupReg_PI - AuthReg_PI = 0") # Sig @ .10


linearHypothesis(SURLibs, "IngroupReg_I - PureReg_I = 0")
linearHypothesis(SURLibs, "IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURLibs, "AuthReg_I - PureReg_I = 0")
linearHypothesis(SURLibs, "AuthReg_PI - PureReg_PI = 0")



##############
# Repubs #####
##############

RepDataParty <- MFQ20[MFQ20$Party.cat == "Republican" & 
                        MFQ20$Treatment != "Ideol",]

vars <- c("HarmTotal.1", "FairTotal.1", "IngroupTotal.1", "AuthTotal.1",
          "PureTotal.1", "Treatment")

RepDataParty <- RepDataParty[vars]
RepDataParty <- na.omit(RepDataParty)

RepDataParty$P <- ifelse(RepDataParty$Treatment == "Party", 1, 0)
RepDataParty$PI <- ifelse(RepDataParty$Treatment == "P + I", 1, 0)


Harm <- HarmTotal.1 ~ P + PI
Fair <- FairTotal.1 ~ P + PI
Ingroup <- IngroupTotal.1 ~ P + PI
Auth <- AuthTotal.1 ~ P + PI
Pure <- PureTotal.1 ~ P + PI


SURReps <- systemfit(list(HarmReg = Harm, FairReg = Fair, IngroupReg = Ingroup,
                          AuthReg = Auth, PureReg = Pure), 
                     data = RepDataParty, method = "SUR")
summary(SURReps)


linearHypothesis(SURReps, "HarmReg_P - FairReg_P = 0")
linearHypothesis(SURReps, "HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURReps, "-HarmReg_P - IngroupReg_P = 0")
linearHypothesis(SURReps, "-HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURReps, "-HarmReg_P - AuthReg_P = 0")
linearHypothesis(SURReps, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURReps, "HarmReg_P - PureReg_P = 0")
linearHypothesis(SURReps, "HarmReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURReps, "-FairReg_P - IngroupReg_P = 0")
linearHypothesis(SURReps, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURReps, "-FairReg_P - AuthReg_P = 0")
linearHypothesis(SURReps, "FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURReps, "FairReg_P - PureReg_P = 0")
linearHypothesis(SURReps, "FairReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURReps, "IngroupReg_P - AuthReg_P = 0")
linearHypothesis(SURReps, "-IngroupReg_PI - AuthReg_PI = 0")


linearHypothesis(SURReps, "-IngroupReg_P - PureReg_P = 0") 
linearHypothesis(SURReps, "-IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURReps, "-AuthReg_P - PureReg_P = 0") 
linearHypothesis(SURReps, "AuthReg_PI - PureReg_PI = 0")


#################
# Conservatives #
#################

ConsDataParty <- MFQ20[MFQ20$Ideol.cat == "Conservative" & 
                         MFQ20$Treatment != "Party",]

vars <- c("HarmTotal.1", "FairTotal.1", "IngroupTotal.1", "AuthTotal.1",
          "PureTotal.1", "Treatment")

ConsDataParty <- ConsDataParty[vars]
ConsDataParty <- na.omit(ConsDataParty)

ConsDataParty$I <- ifelse(ConsDataParty$Treatment == "Ideol", 1, 0)
ConsDataParty$PI <- ifelse(ConsDataParty$Treatment == "P + I", 1, 0)

Harm <- HarmTotal.1 ~ I + PI
Fair <- FairTotal.1 ~ I + PI
Ingroup <- IngroupTotal.1 ~ I + PI
Auth <- AuthTotal.1 ~ I + PI
Pure <- PureTotal.1 ~ I + PI


SURCons <- systemfit(list(HarmReg = Harm, FairReg = Fair, IngroupReg = Ingroup,
                          AuthReg = Auth, PureReg = Pure), 
                     data = ConsDataParty, method = "SUR")
summary(Cons)

linearHypothesis(SURCons, "HarmReg_I - FairReg_I = 0")
linearHypothesis(SURCons, "HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURCons, "-HarmReg_I - IngroupReg_I = 0")
linearHypothesis(SURCons, "-HarmReg_PI - IngroupReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons, "HarmReg_I - AuthReg_I = 0") # Sig @ .01
linearHypothesis(SURCons, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .01


linearHypothesis(SURCons, "HarmReg_I - PureReg_I = 0") # Sig @ .05
linearHypothesis(SURCons, "HarmReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons, "-FairReg_I - IngroupReg_I = 0")
linearHypothesis(SURCons, "-FairReg_PI - IngroupReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons, "FairReg_I - AuthReg_I = 0") # Sig @ .01
linearHypothesis(SURCons, "FairReg_PI - AuthReg_PI = 0") # Sig @ .01


linearHypothesis(SURCons, "FairReg_I - PureReg_I = 0") # Sig @ .05
linearHypothesis(SURCons, "FairReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons, "-IngroupReg_I - AuthReg_I = 0") 
linearHypothesis(SURCons, "-IngroupReg_PI - AuthReg_PI = 0")


linearHypothesis(SURCons, "-IngroupReg_I - PureReg_I = 0")
linearHypothesis(SURCons, "-IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURCons, "AuthReg_I - PureReg_I = 0")
linearHypothesis(SURCons, "AuthReg_PI - PureReg_PI = 0")


